<?php $this->load->view('common/default_header.php');?>
<?php $this->load->view('common/nav.php');?>
<section class="accu">
    <div class="acbox">
        <div class="content">
            <p class="fs16">体验券数量(张)</p>
            <p class="account"><font class="ticket"><?php echo $user_info['ticket'];?></font></p>
        </div>
    </div>
    <ul class="ul-menu weui_media_box nobordb">
        
        <li class="hide"><span>购买体验券</span><span class="btn-fr"><button class="btn btn-warning btn-sm" onclick="javascript:ticketBuy()" >购买</button></span></li>
        <li class="hide" onclick="javascript:location.href='/invite'"><span>推广得券</span><i class="r_ico"></i></li>
		<?php if($ticketConfig['active_share']){?>
		<li><span>分享得券</span><span class="btn-fr"><?php if($share_date!=date("Y-m-d")){?><button class="btn btn-warning btn-sm" onclick="javascript:shareMask()" >分享</button><?php }else{?><button class="btn btn-sm disabled"  >已分享</button> <?php }?></span></li>
		<?php }?>
		<li class="hide" onclick="javascript:location.href='/ticket/activity'"><span>活动得券</span><i class="r_ico"></i></li>
    </ul>
    <div class="relubox">
        <h5 class="hide">购买体验券</h5>
        <p class="hide">单个账户每天限购10张，每张价值10元。需要注意的是，购买的体验券和赠送的体验券使用同样的交易模式，即无论盈亏，平仓/结算时皆失去券值，盈利部分照常计入账户余额。</p>
        <h5 class="hide">推广得券</h5>
        <p class="hide">注册成为经纪人后，可将自己的推广链接（即经纪人也页面或是推广海报上的二维码）发送好友对其进行邀请（扫描）注册。受邀人注册成功后，双方皆可获得一张体验券，邀请主体无获取上限次数，即成功邀请越多，获得的体验券就越多。</p>
        <h5>分享得券</h5>
        <p>当你把体验券都用完了怎么办（体验券数量为0时）？马上分享朋友圈（点击页面右上角分享按钮）成功即可获赠一张体验券。</p>
        <h5 class="hide">活动得券</h5>
        <p class="hide">参与要点啥官方活动可获得相应赠券。详情请留意活动通知。</p>
    </div>
</section>

<script src="<?php echo js_url("/wcp/jquery-1.9.1.min.js"); ?>?20160329001" type="text/javascript"></script>
<script src="<?php echo js_url("/wcp/bootstrap.min.js"); ?>?20160329001" type="text/javascript"></script>
<script src="<?php echo js_url("/wcp/main.js"); ?>?20160329001" type="text/javascript"></script>
<script src="<?php echo js_url("/wcp/bootstrap-dialog.min.js"); ?>?20160329001" type="text/javascript"></script>
<script src="<?php echo js_url("/wcp/jquery.timers.js"); ?>?20160329001" type="text/javascript"></script>
<script src="<?php echo js_url("/wcp/jquery.blockUI.js"); ?>?20160329001" type="text/javascript"></script>

<script>
var amountArr = [1,2,3,5,10];
var z = 2;
var ticketBuyDialog = {};
var ticketBuyHtml	= '<div class="popbg" id="ticketTrade">';
ticketBuyHtml	+=	'<ul class="pul">';
ticketBuyHtml	+=	'<li>选择数量：';
ticketBuyHtml	+=	'<span><button type="button" onclick="changeAmount(\'-\')" class="btn btn-default btn-sm">&nbsp;&nbsp;<font style="padding:0 10px">-</font>&nbsp;&nbsp;</button>&nbsp;&nbsp;';
ticketBuyHtml	+=	'<input type="text" class="form-control inpw text-center input-sm" name="ticketBuyNum" id="ticketBuyNum" value="3">&nbsp;&nbsp;';
ticketBuyHtml	+=	'<button type="button" onclick="changeAmount('+')" class="btn btn-default btn-sm">&nbsp;&nbsp;<font style="padding:0 10px">+</font>&nbsp;&nbsp;</button></span></li>';
ticketBuyHtml	+=	'<li class="dline" style="padding-top:10px;"></li>';
ticketBuyHtml	+=	'<li><span class="pblock">体验券：10元/张</span></li>';
ticketBuyHtml	+=	'<li class="text-center"><botton class="btn btn-warning btnw" onclick="buy()">购买</botton></li></ul></div>';
//市价开仓
function ticketBuy(pid, action){
	ticketBuyDialog = new BootstrapDialog({
	title: '确认购买',
	closeByBackdrop: false,
	closeByKeyboard: false,
	type: BootstrapDialog.TYPE_DEFAULT,
	message: function(dialog) {
		return ticketBuyHtml;
		},
	});
	ticketBuyDialog.open();
}



function shareMask(){
  $.blockUI({ 
    css:{
      top:0,
      opacity: .9,
      left:'43%'
    },
    message: "<img src='<?php echo img_url("/wcp/share.png");?>' width=200 onclick='$.unblockUI();'>" 
  }); 
}

function changeAmount(oper){
	var len = amountArr.length-1;
	if(oper=='-'){
		z--;
	}else{
		z++;
	}
	if(z<=0) z=0;
	if(z>=len) z=len;
	$('#ticketTrade #ticketBuyNum').val(amountArr[z]);
}

function buy(name,action,pid){
  var num = $('#ticketBuyNum').val();
  $.ajax({
    type: "POST",
    url: "/api/ticket/buy",
    dataType: 'json',
    data: {'num':num},
    success: function(data){
      if(data.code==0){
        ticketBuyDialog.close();
      }else{
        ticketBuyDialog.setTitle('错误提示');
        ticketBuyDialog.setMessage(data.message);
        ticketBuyDialog.setButtons([{label: '关闭',action: function(dialog){dialog.close();}}]);
        ticketBuyDialog.open();
      }
    },
    error: function(XHR,textStatus,errorThrown) {
      ticketBuyDialog.setTitle('错误提示');
      ticketBuyDialog.setMessage("请求无效");
      ticketBuyDialog.open();
    }
  });
}

$('body').everyTime('5s',function(){
	$.ajax({
		type: 'GET',
		url: "/ajax/userInfo",
		dataType: 'json',
		success: function(data){
		  $('.account').html(data.ticket);
		}
	});
});

</script>
<?php if(!empty($user_info)) $this->load->view('common/wx_share.php');?>